// This file contains the background script for the Chrome extension. 
// It listens for events and handles the logic for redirecting web pages based on specified conditions.

chrome.runtime.onInstalled.addListener(() => {
    console.log("Extension installed");
    // Set default values
    chrome.storage.sync.set({ redirects: [], enableRedirects: false });
});

// chrome.webRequest.onBeforeRequest.addListener(
//     (details) => {
//         return new Promise((resolve) => {
//             console.log(details);
//             chrome.storage.sync.get(['redirects', 'enableRedirects'], (data) => {
//                 if (!data.enableRedirects) {
//                     resolve({});
//                     return;
//                 }
//                 const redirects = data.redirects || [];
//                 const redirect = redirects.find(r => {
//                     const regex = new RegExp(r.from);
//                     return r.enabled && regex.test(details.url);
//                 });
//                 if (redirect) {
//                     resolve({ redirectUrl: redirect.to });
//                 } else {
//                     resolve({});
//                 }
//             });
//         });
//     },
//     { urls: ["<all_urls>"] }, // Specify the URLs to listen for
//     ["blocking"]
// );